Skip to content

Implement upgrade contract logic#256

Merged
Akshola00 merged 2 commits intoWeb3Novalabs:mainfrom
whiteghost0001:Implement-upgrade_contract-logic
Mar 28, 2026
Merged

Implement upgrade contract logic#256
Akshola00 merged 2 commits intoWeb3Novalabs:mainfrom
whiteghost0001:Implement-upgrade_contract-logic

Conversation

@whiteghost0001
Copy link
Copy Markdown
Contributor

@whiteghost0001 whiteghost0001 commented Mar 26, 2026

Closes #221


The upgrade_contract function already existed and was correctly calling env.deployer().update_current_contract_wasm(new_wasm_hash). The task was really about proving it works with a proper integration test.

The old test was weak — it just passed a zeroed-out hash, expected it to fail, and called that "success". I replaced it with a real integration test that:

Builds the contract's own WASM using contractimport!
Uploads it to get a valid on-ledger hash
Calls upgrade_contract and asserts it succeeds
Verifies the contract is still callable after the upgrade (storage intact)
I also updated the CI workflow to install the wasm32v1-none target and build the WASM before running tests, since contractimport! needs the file present at compile time.

- Add EventMetrics struct with tickets_sold field (zero-initialized)
- Add StorageKey::Event(BytesN<32>) and StorageKey::EventMetrics(BytesN<32>)
- Update EventDetails: id changed to BytesN<32>, added token field
- Implement create_event to persist EventDetails and EventMetrics in storage
- Add state logic test verifying all fields saved correctly in env.storage()
- Replace weak auth-only test with a real integration test that uploads
  the contract's own compiled WASM via contractimport!, calls
  upgrade_contract, and verifies the contract remains functional after
  the upgrade (storage preserved)
- Add test_upgrade_contract_not_initialized_fails test
- Update CI workflow: install wasm32v1-none target and build WASM before
  running tests (contractimport! requires the file at compile time)
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 26, 2026

@whiteghost0001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Akshola00 Akshola00 merged commit 7db8736 into Web3Novalabs:main Mar 28, 2026
1 check passed
@Akshola00
Copy link
Copy Markdown
Contributor

Thanks for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement upgrade_contract logic

2 participants